package com.fuyao.cloud.personnel.problem.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fuyao.cloud.common.core.util.R;
import com.fuyao.cloud.common.data.mybatis.SpliceQueryWrapper;
import com.fuyao.cloud.common.excel.annotation.ResponseExcel;
import com.fuyao.cloud.common.log.annotation.SysLog;
import com.fuyao.cloud.personnel.api.entity.ProblemRectifyDetailed;
import com.fuyao.cloud.personnel.problem.service.ProblemRectifyDetailedService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 整改措施责任关联表
 *
 * @author pigx code generator
 * @date 2022-04-26 10:14:06
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/rectifydetailed" )
@Api(value = "rectifydetailed", tags = "整改措施责任关联表管理")
public class ProblemRectifyDetailedController {

    private final ProblemRectifyDetailedService problemRectifyDetailedService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param problemRectifyDetailed 整改措施责任关联表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page" )
    @PreAuthorize("@pms.hasPermission('problem_rectifydetailed_view')" )
    public R getFyProblemRectifyDetailedPage(Page page, ProblemRectifyDetailed problemRectifyDetailed) {
        return R.ok(problemRectifyDetailedService.problemRectifyDetailedPage(page, SpliceQueryWrapper.spliceSearchCondition(problemRectifyDetailed)));
    }


    /**
     * 通过id查询整改措施责任关联表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{id}")
    @PreAuthorize("@pms.hasPermission('problem_rectifydetailed_view')" )
    public R getById(@PathVariable("id" ) Long id) {
        return R.ok(problemRectifyDetailedService.getById(id));
    }

    /**
     * 新增整改措施责任关联表
     * @param problemRectifyDetailed 整改措施责任关联表
     * @return R
     */
    @ApiOperation(value = "新增整改措施责任关联表", notes = "新增整改措施责任关联表")
    @SysLog("新增整改措施责任关联表" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('problem_rectifydetailed_add')" )
    public R save(@RequestBody ProblemRectifyDetailed problemRectifyDetailed) {
        return R.ok(problemRectifyDetailedService.save(problemRectifyDetailed));
    }

    /**
     * 新增整改措施责任关联表
     * @param problemRectifyDetaileds 整改措施责任关联表
     * @return R
     */
    @ApiOperation(value = "新增整改措施责任关联表", notes = "新增整改措施责任关联表")
    @SysLog("新增整改措施责任关联表")
    @PostMapping("/saveList")
    @PreAuthorize("@pms.hasPermission('problem_rectifydetailed_add')" )
    public R saveList(@RequestBody List<ProblemRectifyDetailed> problemRectifyDetaileds) {
        return R.ok(problemRectifyDetailedService.saveOrUpdateBatch(problemRectifyDetaileds));
    }

    /**
     * 修改整改措施责任关联表
     * @param problemRectifyDetailed 整改措施责任关联表
     * @return R
     */
    @ApiOperation(value = "修改整改措施责任关联表", notes = "修改整改措施责任关联表")
    @SysLog("修改整改措施责任关联表" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('problem_rectifydetailed_edit')" )
    public R updateById(@RequestBody ProblemRectifyDetailed problemRectifyDetailed) {
        return R.ok(problemRectifyDetailedService.updateById(problemRectifyDetailed));
    }

    /**
     * 通过id删除整改措施责任关联表
     * @param id id
     * @return R
     */
    @ApiOperation(value = "通过id删除整改措施责任关联表", notes = "通过id删除整改措施责任关联表")
    @SysLog("通过id删除整改措施责任关联表" )
    @DeleteMapping("/{id}" )
    @PreAuthorize("@pms.hasPermission('problem_rectifydetailed_del')" )
    public R removeById(@PathVariable Long id) {
        return R.ok(problemRectifyDetailedService.removeById(id));
    }


    /**
     * 导出excel 表格
     * @param problemRectifyDetailed 查询条件
     * @return excel 文件流
     */
    @ResponseExcel
    @GetMapping("/export")
    @PreAuthorize("@pms.hasPermission('problem_rectifydetailed_export')" )
    public List<ProblemRectifyDetailed> export(ProblemRectifyDetailed problemRectifyDetailed) {
        return problemRectifyDetailedService.list(Wrappers.query(problemRectifyDetailed));
    }

    /**
     * 分页查询
     * @param problemRectifyDetailed 整改措施责任关联表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/list" )
    @PreAuthorize("@pms.hasPermission('problem_rectifydetailed_view')" )
    public R getProblemRectifyDetailedList(ProblemRectifyDetailed problemRectifyDetailed) {
        return R.ok(problemRectifyDetailedService.list(Wrappers.query(problemRectifyDetailed)));
    }
}
